<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/public/libs/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/public/libs/layui/css/global.css" media="all">
    <script src="/public/libs/jquery/jquery.min.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
        html,
        body {
            margin: 15px;
        }
    </style>
</head>

<body>
    <div class="site-title">
        <fieldset>
            <legend><a name="use">添加平台</a></legend>
        </fieldset>
    </div>
    <form class="layui-form" action="#" style="width: 600px;">
        <div class="layui-form-item">
            <label class="layui-form-label">平台名称</label>
            <div class="layui-input-block">
                <input type="text" name="platform" required lay-verify="required" placeholder="请输入平台名称" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input type="checkbox" name="enable" lay-skin="switch" checked>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="description" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submitForm">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script src="/public/libs/layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
    <script>
        layui.use('form', function () {
            var form = layui.form;
            form.on('submit(submitForm)', function (data) {
                layer.msg(JSON.stringify(data.field));
                $.post("/platform/add", data.field, function (res) {
                    console.log(`==> ${res}`);
                }, "json");
                return false;
            });
        });
    </script>
</body>

</html>